import {request, config} from 'utils'

const {api} = config
const {content, role, region} = api
const {
  findAllLinkUrl,
  insertLinkUrl,
  findAllPubLinkUrl,
  // removeLinkPubUrl,
  removeLinkUrl,
  removesLinkUrl,
  updateLinkUrl,
  // insertLinkPubUrl,

  insertPubLinkRoleUrl,
  insertPubLinkComUrl,

  removePubLinkRoleUrl,
  removePubLinkComUrl,
  getPgPletIdUrl,

  queryAll, remove, update, insert, removes,
} = content.link
const {findAllRoleUrl} = role
const {findAllRegionUrl} = region

//请求已录入链接 table数据
export function findAllLink (params) {
  return request({
    url: findAllLinkUrl,
    method: 'get',
    data: params,
  })
}

// 分类插入链接
export function insertLinkPub (params) {
  let {toWho} = params
  // 默认按单位发布
  let url = insertPubLinkComUrl
  if (toWho === 'role') {
    url = insertPubLinkRoleUrl
  }
  return request({
    url: url,
    method: 'get',
    data: params,
  })
}

//切换tab时获取全部发布完链接的数据
export function findAllPubLink (params) {
  return request({
    url: findAllPubLinkUrl,
    method: 'get',
    data: params,
  })
}

// 已发布文章 单选删除
export function removeLinkPub (params) {
  let linkPubFilterType = window.localStorage.getItem("linkPubFilterType")
  let url = removePubLinkComUrl
  if (linkPubFilterType === 'role') {
    url = removePubLinkRoleUrl
  }
  return request({
    url: url,
    method: 'get',
    data: params,
  })
}

//多选删除
export function removeLinks (params) {
  return request({
    url: removesLinkUrl,
    method: 'get',
    data: params,
  })
}


//table单选删除
export function removeLink (params) {
  return request({
    url: removeLinkUrl,
    method: 'get',
    data: params,
  })
}


// 创建 编辑
export function insertLink (params) {
  return request({
    url: insertLinkUrl,
    method: 'get',
    data: params,
  })
}

//编辑完后重新请求table数据
export function updateLink (params) {
  return request({
    url: updateLinkUrl,
    method: 'get',
    data: params,
  })
}

export function getPubTarget (params) {
  let url = findAllRoleUrl
  // 默认角色发布，可选单位发布
  if (params.toWho === 'region') {
    url = findAllRegionUrl
  }
  return request({
    url: url,
    method: 'get',
  })
}

export function getPgPletIdLink (params) {
  return request({
    url: getPgPletIdUrl,
    method: 'get',
    data: params,
  })
}
